package cn.funnyxb.powerremember.uis.task.taskEdit;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import cn.funnyxb.powerremember.beans.ATask;
import cn.funnyxb.powerremember.beans.AlarmInfo;
import cn.funnyxb.powerremember.beans.WordBase;
import cn.funnyxb.powerremember.db.AllTables;
import cn.funnyxb.powerremember.uis.task.taskEdit.alarm.AlarmEditActivity;
import cn.funnyxb.tools.appFrame.App;
import cn.funnyxb.tools.appFrame.activityFrame.ActivitysHolder;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import cn.funnyxb.tools.appFrame.util.DatetimeTool;
import cn.funnyxb.tools.appFrame.util.ui.UIChanger;
import com.mobclick.android.MobclickAgent;
import java.util.ArrayList;
import java.util.Iterator;

public class TaskEditActivity extends Activity
  implements IUI_TaskEdit
{
  private static final int DIALOGID_inputGroupOfOneDay = 120;
  private static final int DIALOGID_inputGroupSize = 110;
  private static final int DIALOGID_inputName = 100;
  private static final int DIALOGID_inputName_includeSpecialChar = 103;
  private static final int DIALOGID_inputName_nameIsExist = 105;
  public static final String EXTRA_TASKINFO = "taskinfo";
  public static final String EXTRA_TASKMODE = "taskmode";
  protected static final int REQUESTCODE_ALARMEDIT = 1;
  public static final int TASKMODE_CREATE = 1;
  public static final int TASKMODE_EDIT = 2;
  private Adapter_TaskEdit_Alarms adapter_alarms;
  private ArrayList<AlarmInfo> alarmInfoList;
  private AdapterView.OnItemClickListener alarmItemClickListener = new 2(this);
  private AdapterView.OnItemLongClickListener alarmItemLongClickListener = new 3(this);
  private View.OnClickListener btnOnclickListener = new 1(this);
  private int oldGroupSize = -1;
  private IProccessor_TaskEdit proccessor;
  private ProgressDialog progressDialog_saving;
  private ProgressDialog progressDialog_waitingLoad;
  private ATask taskInfo;
  private int taskMode;

  private void changeMainView(boolean paramBoolean)
  {
    View localView1 = findViewById(2131165282);
    View localView2 = findViewById(2131165294);
    String str1 = getString(2131034226);
    String str2 = getString(2131034227);
    String str3 = getString(2131034228);
    String str4 = getString(2131034229);
    if (paramBoolean)
    {
      log("to show adv");
      ListView localListView = (ListView)findViewById(2131165301);
      if (localListView.getAdapter() == null)
      {
        log("setAdapter");
        localListView.setAdapter(this.adapter_alarms);
      }
      hideSoftInput();
      Toast.makeText(this, 2131034230, 1).show();
      StringBuilder localStringBuilder2 = new StringBuilder(String.valueOf(getString(2131034112))).append("--");
      if (this.taskMode == 1);
      for (String str6 = str1; ; str6 = str2)
      {
        setTitle(str6 + "-->2、" + str4);
        UIChanger.changeViewAtSamePos_alpha(localView2, localView1, 500, 500);
        label174: return;
      }
    }
    StringBuilder localStringBuilder1 = new StringBuilder(String.valueOf(getString(2131034112))).append("--");
    if (this.taskMode == 1);
    for (String str5 = str1; ; str5 = str2)
    {
      setTitle(str5 + "-->1、" + str3);
      UIChanger.changeViewAtSamePos_alpha(localView1, localView2, 500, 500);
      break label174:
    }
  }

  private boolean checkGroupOfOneDayIsValid()
  {
    int j;
    int i;
    try
    {
      j = Integer.parseInt(((EditText)findViewById(2131165293)).getText().toString());
      if (j > 0)
        break label47;
      showDialog(120);
      i = 0;
      label33: label47: return i;
    }
    catch (Exception localException)
    {
      showDialog(120);
      i = 0;
      break label33:
      this.taskInfo.setGroupOfOneDay(j);
      i = 1;
    }
  }

  private boolean checkGroupSizeIsValid()
  {
    int j;
    int i;
    try
    {
      j = Integer.parseInt(((EditText)findViewById(2131165292)).getText().toString());
      if (j > 0)
        break label47;
      showDialog(110);
      i = 0;
      label33: label47: return i;
    }
    catch (Exception localException)
    {
      showDialog(110);
      i = 0;
      break label33:
      this.taskInfo.setGroupSize(j);
      i = 1;
    }
  }

  private void checkMode()
  {
    this.taskMode = getIntent().getIntExtra("taskmode", -1);
    if ((this.taskMode == 1) || (this.taskMode == 2))
      return;
    Toast.makeText(this, 2131034147, 1).show();
    finish();
  }

  private boolean checkNameIsValid()
  {
    String str = ((EditText)findViewById(2131165288)).getEditableText().toString().trim();
    if (str.length() < 1)
      showDialog(100);
    for (int i = 0; ; i = 1)
    {
      while (true)
      {
        return i;
        if (!(str.matches("\\w+")))
        {
          showDialog(103);
          i = 0;
        }
        if ((this.taskMode != 1) || (!(this.proccessor.isTaskNameExist(str))))
          break;
        showDialog(105);
        i = 0;
      }
      this.taskInfo.setName(str);
    }
  }

  private void createAlarm()
  {
    Intent localIntent = new Intent(this, AlarmEditActivity.class);
    localIntent.putExtra(AlarmEditActivity.EXTRA_EDITINGPOS, -1);
    AlarmInfo localAlarmInfo = AlarmInfo.getExample_morning();
    localAlarmInfo.setTime(DatetimeTool.getTimeInHHMM(System.currentTimeMillis()));
    localIntent.putExtra(AlarmEditActivity.EXTRA_ALARMINFO, localAlarmInfo);
    startActivityForResult(localIntent, 1);
  }

  private void dismissProgressDialog_waitingLoad()
  {
    if ((this.progressDialog_waitingLoad == null) || (!(this.progressDialog_waitingLoad.isShowing())))
      return;
    this.progressDialog_waitingLoad.dismiss();
  }

  private void freashWordBaseSpinner(ArrayList<WordBase> paramArrayList)
  {
    ((Spinner)findViewById(2131165290)).setAdapter(new ArrayAdapter(this, 17367048, 16908308, paramArrayList));
  }

  private void hideSoftInput()
  {
    ((InputMethodManager)getSystemService("input_method")).hideSoftInputFromWindow(findViewById(2131165282).getWindowToken(), 0);
  }

  private void initFrame()
  {
    findViewById(2131165286).setBackgroundResource(17301654);
    findViewById(2131165301).setBackgroundResource(17301654);
    Spinner localSpinner = (Spinner)findViewById(2131165290);
    ((EditText)findViewById(2131165292)).setText(this.taskInfo.getGroupSize());
    ((EditText)findViewById(2131165293)).setText(this.taskInfo.getGroupOfOneDay());
    if (this.taskMode == 2)
    {
      ((EditText)findViewById(2131165288)).setText(this.taskInfo.getName());
      ((EditText)findViewById(2131165288)).setEnabled(false);
      ((TextView)findViewById(2131165287)).setText(getString(2131034261) + ":(" + getString(2131034157) + ")");
      ((TextView)findViewById(2131165289)).setText(getString(2131034262) + ":(" + getString(2131034157) + ")");
      String[] arrayOfString = new String[1];
      arrayOfString[0] = this.taskInfo.getWordBaseName();
      localSpinner.setAdapter(new ArrayAdapter(this, 17367048, arrayOfString));
      localSpinner.setEnabled(false);
      ((TextView)findViewById(2131165291)).setText(getString(2131034263) + ":" + this.taskInfo.getWordCnt());
    }
    while (true)
    {
      findViewById(2131165284).setOnClickListener(this.btnOnclickListener);
      findViewById(2131165299).setOnClickListener(this.btnOnclickListener);
      findViewById(2131165285).setOnClickListener(this.btnOnclickListener);
      findViewById(2131165298).setOnClickListener(this.btnOnclickListener);
      findViewById(2131165300).setOnClickListener(this.btnOnclickListener);
      ((ListView)findViewById(2131165301)).setOnItemClickListener(this.alarmItemClickListener);
      ((ListView)findViewById(2131165301)).setOnItemLongClickListener(this.alarmItemLongClickListener);
      findViewById(2131165295).setOnClickListener(this.btnOnclickListener);
      return;
      initSpinner(localSpinner);
    }
  }

  private void initSpinner(Spinner paramSpinner)
  {
    paramSpinner.setOnItemSelectedListener(new 4(this));
  }

  private boolean isInputValidOfBasePage()
  {
    if (!(checkNameIsValid()));
    for (int i = 0; ; i = 1)
      while (true)
      {
        return i;
        if (!(checkGroupOfOneDayIsValid()))
          i = 0;
        if (checkGroupSizeIsValid())
          break;
        i = 0;
      }
  }

  private void log(String paramString)
  {
    Debuger.log("taskedit", paramString);
  }

  private void prepareAlarmsInfo()
  {
    if (this.taskMode == 1)
    {
      this.alarmInfoList = new ArrayList();
      this.alarmInfoList.add(AlarmInfo.getExample_morning());
      this.alarmInfoList.add(AlarmInfo.getExample_noon());
      this.alarmInfoList.add(AlarmInfo.getExample_night());
      this.adapter_alarms = new Adapter_TaskEdit_Alarms(this, this.alarmInfoList);
    }
    while (true)
    {
      return;
      this.proccessor.asyncLoadAlarms(this.taskInfo.getId());
    }
  }

  private void prepareProgressDialog_waitingLoad()
  {
    if (this.progressDialog_waitingLoad == null)
      this.progressDialog_waitingLoad = new ProgressDialog(this);
    this.progressDialog_waitingLoad.setTitle(2131034131);
    this.progressDialog_waitingLoad.setMessage(getString(2131034132));
  }

  private void prepareShowAdvPage()
  {
    if (!(isInputValidOfBasePage()));
    while (true)
    {
      return;
      if ((this.taskMode == 2) && (this.oldGroupSize != this.taskInfo.getGroupSize()))
        new AlertDialog.Builder(this).setTitle(2131034264).setMessage(2131034265).setPositiveButton(2131034266, new 5(this)).setNegativeButton(2131034267, new 6(this)).create().show();
      changeMainView(true);
    }
  }

  private void prepareTaskInfo()
  {
    if (this.taskMode == 1)
      this.taskInfo = new ATask();
    while (true)
    {
      return;
      this.taskInfo = ((ATask)getIntent().getSerializableExtra("taskinfo"));
      if (this.taskInfo == null)
      {
        Toast.makeText(this, 2131034147, 1).show();
        finish();
      }
      this.oldGroupSize = this.taskInfo.getGroupSize();
    }
  }

  private void prepareWordBases()
  {
    if (this.taskMode != 1)
      return;
    this.proccessor.asyncLoadWordBases();
  }

  private void submit()
  {
    Spinner localSpinner = (Spinner)findViewById(2131165290);
    String str = "";
    if (this.taskMode == 1)
    {
      log("sp.getSelectedItem=" + localSpinner.getSelectedItem());
      str = AllTables.getTbName_words(((WordBase)localSpinner.getSelectedItem()).getTbExtName());
    }
    log("wordBaseName=" + str);
    ArrayList localArrayList = this.adapter_alarms.getAllAlarms();
    int i = 1;
    Iterator localIterator = localArrayList.iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        this.proccessor.asyncSubmit(this.taskMode, this.oldGroupSize, this.taskInfo, localArrayList, str);
        return;
      }
      AlarmInfo localAlarmInfo = (AlarmInfo)localIterator.next();
      StringBuilder localStringBuilder = new StringBuilder("alarm: ");
      int j = i + 1;
      log(i + "time=" + localAlarmInfo.getTime_hh() + ":" + localAlarmInfo.getTime_mm());
      i = j;
    }
  }

  public void notifyAlarmsLoaded(ArrayList<AlarmInfo> paramArrayList)
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      dismissProgressDialog_waitingLoad();
      this.adapter_alarms = new Adapter_TaskEdit_Alarms(this, paramArrayList);
    }
  }

  public void notifyDelOldDbing()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      this.progressDialog_saving.setMessage("正在清理数据..");
    }
  }

  public void notifyRegAlarm2Ssytem()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      this.progressDialog_saving.setMessage("正在注册提醒服务...");
    }
  }

  public void notifySubmited()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      if ((this.progressDialog_saving != null) && (this.progressDialog_saving.isShowing()))
        this.progressDialog_saving.dismiss();
      this.progressDialog_saving = null;
      new AlertDialog.Builder(this).setTitle(2131034130).setMessage("任务操作成功").setPositiveButton(2131034133, new 7(this)).create().show();
    }
  }

  public void notifyUnRegAllSystemAlarming()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      this.progressDialog_saving.setMessage("正在取消原提醒服务..");
    }
  }

  public void notifyUpdateDbing()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      this.progressDialog_saving.setMessage("正在更新数据...");
    }
  }

  public void notifyWaitingLoadAlarms()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      prepareProgressDialog_waitingLoad();
      this.progressDialog_waitingLoad.show();
    }
  }

  public void notifyWaitingLoadWordBases()
  {
    prepareProgressDialog_waitingLoad();
    this.progressDialog_waitingLoad.show();
  }

  public void notifyWaitingSubmit()
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      if (this.progressDialog_saving == null)
        this.progressDialog_saving = new ProgressDialog(this);
      this.progressDialog_saving.setTitle(2131034131);
      this.progressDialog_saving.setMessage(getString(2131034142));
      this.progressDialog_saving.setCancelable(false);
      this.progressDialog_saving.show();
    }
  }

  public void notifyWordBasesLoaded(ArrayList<WordBase> paramArrayList)
  {
    if ((isFinishing()) || (isRestricted()));
    while (true)
    {
      return;
      dismissProgressDialog_waitingLoad();
      log("notify freah wordbases,cnt=" + paramArrayList.size());
      freashWordBaseSpinner(paramArrayList);
    }
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if (paramInt1 != 1);
    while (true)
    {
      return;
      if ((paramInt2 != -1) || (paramIntent == null))
        continue;
      int i = paramIntent.getIntExtra(AlarmEditActivity.EXTRA_EDITINGPOS, -2);
      AlarmInfo localAlarmInfo = (AlarmInfo)paramIntent.getSerializableExtra(AlarmEditActivity.EXTRA_ALARMINFO);
      if (i <= -2)
        continue;
      if (i != -1)
      {
        localAlarmInfo.setEnabled(true);
        this.adapter_alarms.editItem(i, localAlarmInfo);
      }
      localAlarmInfo.setEnabled(true);
      this.adapter_alarms.addItem(localAlarmInfo);
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    log("oncreate");
    checkMode();
    prepareTaskInfo();
    this.proccessor = new Proccessor_TaskEdit(this);
    setContentView(2130903052);
    initFrame();
    prepareWordBases();
    prepareAlarmsInfo();
  }

  public Dialog onCreateDialog(int paramInt)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
    localBuilder.setTitle(2131034130);
    switch (paramInt)
    {
    default:
    case 100:
    case 103:
    case 105:
    case 110:
    case 120:
    }
    while (true)
    {
      localBuilder.setNegativeButton(2131034158, null);
      return localBuilder.create();
      localBuilder.setMessage(2131034268);
      continue;
      localBuilder.setMessage(2131034269);
      continue;
      localBuilder.setMessage(2131034270);
      continue;
      localBuilder.setMessage(2131034271);
      continue;
      localBuilder.setMessage(2131034272);
    }
  }

  protected void onDestroy()
  {
    log("ondestroy");
    this.proccessor.destroy();
    super.onDestroy();
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramInt == 4) && (paramKeyEvent.getRepeatCount() == 0) && (findViewById(2131165294).getVisibility() == 0))
      changeMainView(false);
    for (boolean bool = true; ; bool = super.onKeyDown(paramInt, paramKeyEvent))
      return bool;
  }

  protected void onPause()
  {
    super.onPause();
    MobclickAgent.onPause(this);
  }

  protected void onRestart()
  {
    super.onRestart();
    log("onRestart");
  }

  protected void onResume()
  {
    super.onResume();
    MobclickAgent.onResume(this);
    App.getApp().getActivitysHolder().regCurrentActivity(this);
    log("onresume");
  }

  protected void onStart()
  {
    super.onStart();
    log("onstart");
  }

  protected void onStop()
  {
    log("onstop");
    super.onStop();
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.powerremember.uis.task.taskEdit.TaskEditActivity
 * JD-Core Version:    0.5.3
 */